home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume18 / cproto / patch02 next >
Encoding:
Internet Message Format  |  1991-04-10  |  8.9 KB

  1. From: cthuang@contact.UUCP (Chin Huang)
  2. Newsgroups: comp.sources.misc
  3. Subject: v18i006:  cproto - Generate C function prototypes from C source, Patch02
  4. Message-ID: <1991Apr10.034840.3369@sparky.IMD.Sterling.COM>
  5. Date: 10 Apr 91 03:48:40 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 95078609 33bd6fd1 f7a6f202 a340839f
  8.  
  9. Submitted-by: Chin Huang <cthuang@contact.UUCP>
  10. Posting-number: Volume 18, Issue 6
  11. Archive-name: cproto/patch02
  12. Patch-To: cproto: Volume 17, Issue 70-71
  13.  
  14. Here is patch 2 to cproto, a C function prototype generator.
  15. This patch enables cproto to scan lex and yacc source files for
  16. function definitions.  It also fixes a problem that may cause
  17. segmentation faults.
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of shell archive."
  26. # Contents:  patch2
  27. # Wrapped by ibmpc@laphroig.UUCP on Thu Apr 04 16:53:33 1991
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f patch2 -a "${1}" != "-c" ; then 
  30.   echo shar: Will not over-write existing file \"patch2\"
  31. else
  32. echo shar: Extracting \"patch2\" \(6854 characters\)
  33. sed "s/^X//" >patch2 <<'END_OF_patch2'
  34. Xdiff -c old/CHANGES ./CHANGES
  35. X*** old/CHANGES    Wed Apr 03 21:42:20 1991
  36. X--- ./CHANGES    Wed Apr 03 21:52:24 1991
  37. X***************
  38. X*** 1,5 ****
  39. X--- 1,15 ----
  40. X  Version 2
  41. X  
  42. X+ Patchlevel 2
  43. X+ 
  44. X+ - Cproto is now able to generate prototypes for functions defined in lex
  45. X+   and yacc source files named on the command line.  Lex and yacc source
  46. X+   files are recognized by the .l or .y extension.
  47. X+ - Fix: The memory allocated to the typedef symbol table was not being
  48. X+   freed after scanning each source file.
  49. X+ - Fix: Failing to reset a variable during error recovery caused
  50. X+   segmentation faults.
  51. X+ 
  52. X  Patchlevel 1
  53. X  
  54. X  - Fix: Cproto incorrectly generated the parameter "int ..." in
  55. Xdiff -c old/grammar.y ./grammar.y
  56. X*** old/grammar.y    Wed Apr 03 21:42:26 1991
  57. X--- ./grammar.y    Wed Apr 03 21:52:28 1991
  58. X***************
  59. X*** 1,4 ****
  60. X! /* $Id: grammar.y 2.2 91/03/30 13:19:00 cthuang Exp $
  61. X   *
  62. X   * yacc grammar for C prototype generator
  63. X   * This was derived from the grammar given in Appendix A of
  64. X--- 1,4 ----
  65. X! /* $Id: grammar.y 2.3 91/04/03 21:27:01 cthuang Exp $
  66. X   *
  67. X   * yacc grammar for C prototype generator
  68. X   * This was derived from the grammar given in Appendix A of
  69. X***************
  70. X*** 558,563 ****
  71. X--- 558,564 ----
  72. X  yyerror (msg)
  73. X  char *msg;
  74. X  {
  75. X+     func_params = FALSE;
  76. X      output_error();
  77. X      fprintf(stderr, "%s\n", msg);
  78. X  }
  79. X***************
  80. X*** 565,572 ****
  81. X  void
  82. X  parse_file ()
  83. X  {
  84. X      printf("/* %s */\n", cur_file);
  85. X-     line_num = 1;
  86. X      typedef_names = create_symbol_table();
  87. X      yyparse();
  88. X  }
  89. X--- 566,583 ----
  90. X  void
  91. X  parse_file ()
  92. X  {
  93. X+     char *s;
  94. X+ 
  95. X+     if (strlen(cur_file) > 2) {
  96. X+     s = cur_file + strlen(cur_file) - 2;
  97. X+     if (strcmp(s, ".l") == 0 || strcmp(s, ".y") == 0)
  98. X+         BEGIN LEXYACC;
  99. X+     }
  100. X+ 
  101. X      printf("/* %s */\n", cur_file);
  102. X      typedef_names = create_symbol_table();
  103. X+     line_num = 1;
  104. X+     ly_count = 0;
  105. X      yyparse();
  106. X+     destroy_symbol_table(typedef_names);
  107. X  }
  108. Xdiff -c old/lex.l ./lex.l
  109. X*** old/lex.l    Thu Mar 28 15:41:56 1991
  110. X--- ./lex.l    Wed Apr 03 21:52:26 1991
  111. X***************
  112. X*** 1,5 ****
  113. X  %{
  114. X! /* $Id: lex.l 2.1 91/03/25 11:40:27 cthuang Exp $
  115. X   *
  116. X   * C function prototype generator
  117. X   * Lexical analyzer specification
  118. X--- 1,5 ----
  119. X  %{
  120. X! /* $Id: lex.l 2.2 91/04/03 21:31:11 cthuang Exp $
  121. X   *
  122. X   * C function prototype generator
  123. X   * Lexical analyzer specification
  124. X***************
  125. X*** 17,22 ****
  126. X--- 17,23 ----
  127. X  char cur_file[MAX_TEXT_LENGTH];    /* current file name */
  128. X  int line_num = 1;        /* current line number in file */
  129. X  static int curly = 0;        /* number of curly brace nesting levels */
  130. X+ static int ly_count = 0;    /* number of occurances of %% */
  131. X  
  132. X  typedef struct {
  133. X      FILE *fp;
  134. X***************
  135. X*** 29,38 ****
  136. X  static void do_include();
  137. X  %}
  138. X  
  139. X! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT
  140. X  %%
  141. X  
  142. X  \n            ++line_num;
  143. X  
  144. X  <INITIAL>^#{WS}*    BEGIN CPP1;
  145. X  <CPP1>define{WS}+{ID}.*\\$    {
  146. X--- 30,47 ----
  147. X  static void do_include();
  148. X  %}
  149. X  
  150. X! %s CPP1 CPP2 INIT1 INIT2 CURLY COMMENT LEXYACC
  151. X  %%
  152. X  
  153. X  \n            ++line_num;
  154. X+ 
  155. X+ <LEXYACC>^"%%"        {
  156. X+                 if (++ly_count >= 2)
  157. X+                 BEGIN INITIAL;
  158. X+             }
  159. X+ <LEXYACC>^"%{"        BEGIN INITIAL;
  160. X+ <LEXYACC>.        ;
  161. X+ <INITIAL>^"%}"        BEGIN LEXYACC;
  162. X  
  163. X  <INITIAL>^#{WS}*    BEGIN CPP1;
  164. X  <CPP1>define{WS}+{ID}.*\\$    {
  165. Xdiff -c old/Makefile ./Makefile
  166. X*** old/Makefile    Wed Apr 03 21:42:28 1991
  167. X--- ./Makefile    Wed Apr 03 21:52:26 1991
  168. X***************
  169. X*** 1,4 ****
  170. X! # $Id: Makefile 2.2 91/03/30 13:19:06 cthuang Exp $
  171. X  #
  172. X  # MSDOS makefile for C prototype generator
  173. X  
  174. X--- 1,4 ----
  175. X! # $Id: Makefile 2.3 91/04/03 21:26:50 cthuang Exp $
  176. X  #
  177. X  # MSDOS makefile for C prototype generator
  178. X  
  179. X***************
  180. X*** 34,40 ****
  181. X      $(LEX) lex.l
  182. X  
  183. X  cproto.man: cproto.1
  184. X!     cawf -man $*.1 >$@
  185. X  
  186. X  TAGS: $(SOURCES)
  187. X      etags -t $(SOURCES)
  188. X--- 34,40 ----
  189. X      $(LEX) lex.l
  190. X  
  191. X  cproto.man: cproto.1
  192. X!     cawf -man $*.1 | bsfilt - >$@
  193. X  
  194. X  TAGS: $(SOURCES)
  195. X      etags -t $(SOURCES)
  196. X***************
  197. X*** 63,71 ****
  198. X  zip:
  199. X      pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l
  200. X  
  201. X! ci:
  202. X      ci -u2 $(DIST1) $(DIST3)
  203. X      ci -u2 $(DIST4)
  204. X  
  205. X  # DO NOT DELETE THIS LINE -- make depend depends on it.
  206. X  
  207. X--- 63,75 ----
  208. X  zip:
  209. X      pkzip -u cproto README CHANGES Makefile.* *.1 *.c *.h grammar.y lex.l
  210. X  
  211. X! ci: rmcr
  212. X      ci -u2 $(DIST1) $(DIST3)
  213. X      ci -u2 $(DIST4)
  214. X+ 
  215. X+ rmcr:
  216. X+     rmcr $(DIST1) $(DIST3)
  217. X+     rmcr $(DIST4)
  218. X  
  219. X  # DO NOT DELETE THIS LINE -- make depend depends on it.
  220. X  
  221. Xdiff -c old/patchlev.h ./patchlev.h
  222. X*** old/patchlev.h    Wed Apr 03 21:42:30 1991
  223. X--- ./patchlev.h    Wed Apr 03 21:52:28 1991
  224. X***************
  225. X*** 1,1 ****
  226. X! #define PATCHLEVEL 1
  227. X--- 1,1 ----
  228. X! #define PATCHLEVEL 2
  229. Xdiff -c old/symbol.c ./symbol.c
  230. X*** old/symbol.c    Thu Mar 28 15:42:00 1991
  231. X--- ./symbol.c    Wed Apr 03 21:52:32 1991
  232. X***************
  233. X*** 1,4 ****
  234. X! /* $Id: symbol.c 2.1 91/02/28 11:16:35 cthuang Exp $
  235. X   *
  236. X   * Symbol table maintenance. Implements an abstract data type called
  237. X   * the symbol table.
  238. X--- 1,4 ----
  239. X! /* $Id: symbol.c 2.2 91/04/03 21:30:54 cthuang Exp $
  240. X   *
  241. X   * Symbol table maintenance. Implements an abstract data type called
  242. X   * the symbol table.
  243. X***************
  244. X*** 7,12 ****
  245. X--- 7,13 ----
  246. X  #include "config.h"
  247. X  #include "symbol.h"
  248. X  
  249. X+ 
  250. X  /* Create a symbol table.
  251. X   * Return a pointer to the symbol table or NULL if an error occurs.
  252. X   */
  253. X***************
  254. X*** 24,36 ****
  255. X  }
  256. X  
  257. X  
  258. X  /* This is a simple hash function mapping a symbol name to a hash bucket. */
  259. X  
  260. X! static int
  261. X  hash (name)
  262. X  char *name;
  263. X  {
  264. X!     return (name[0] + name[1] + strlen(name)) % SYM_MAX_HASH;
  265. X  }
  266. X  
  267. X  
  268. X--- 25,65 ----
  269. X  }
  270. X  
  271. X  
  272. X+ /* Free the memory allocated to the symbol table.
  273. X+  */
  274. X+ void
  275. X+ destroy_symbol_table (symtab)
  276. X+ SymbolTable *symtab;
  277. X+ {
  278. X+     int i;
  279. X+     Symbol *sym, *next;
  280. X+ 
  281. X+     for (i = 0; i < SYM_MAX_HASH; ++i) {
  282. X+     sym = symtab->bucket[i];
  283. X+     while (sym != NULL) {
  284. X+         next = sym->next;
  285. X+         free(sym->name);
  286. X+         free(sym);
  287. X+         sym = next;
  288. X+     }
  289. X+     }
  290. X+ }
  291. X+ 
  292. X+ 
  293. X  /* This is a simple hash function mapping a symbol name to a hash bucket. */
  294. X  
  295. X! static unsigned int
  296. X  hash (name)
  297. X  char *name;
  298. X  {
  299. X!     char *s;
  300. X!     unsigned int h;
  301. X! 
  302. X!     h = 0;
  303. X!     s = name;
  304. X!     while (*s != '\0')
  305. X!     h += *s++;
  306. X!     return h % SYM_MAX_HASH;
  307. X  }
  308. X  
  309. X  
  310. Xdiff -c old/symbol.h ./symbol.h
  311. X*** old/symbol.h    Thu Mar 28 15:41:58 1991
  312. X--- ./symbol.h    Wed Apr 03 21:52:30 1991
  313. X***************
  314. X*** 1,4 ****
  315. X! /* $Id: symbol.h 2.1 91/02/28 11:16:22 cthuang Exp $
  316. X   *
  317. X   * Definitions for a symbol table
  318. X   */
  319. X--- 1,4 ----
  320. X! /* $Id: symbol.h 2.2 91/04/03 21:30:33 cthuang Exp $
  321. X   *
  322. X   * Definitions for a symbol table
  323. X   */
  324. X***************
  325. X*** 18,23 ****
  326. X--- 18,24 ----
  327. X  } SymbolTable;
  328. X  
  329. X  extern SymbolTable *create_symbol_table();    /* Create symbol table */
  330. X+ extern void destroy_symbol_table();        /* Create symbol table */
  331. X  extern Symbol *find_symbol();            /* Lookup symbol name */
  332. X  extern Symbol *new_symbol();            /* Define new symbol */
  333. X  
  334. END_OF_patch2
  335. if test 6854 -ne `wc -c <patch2`; then
  336.     echo shar: \"patch2\" unpacked with wrong size!
  337. fi
  338. # end of overwriting check
  339. fi
  340. echo shar: End of shell archive.
  341. exit 0
  342. -- 
  343. Chin Huang  cthuang@contact.uucp  chin.huang%canrem@lsuc.on.ca
  344.  
  345.  
  346. exit 0 # Just in case...
  347. -- 
  348. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  349. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  350. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  351. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  352.